<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/29
 * Time: 16:45
 * 通知页面
 */
require "includes/OrderClass.php";
require "includes/loadwx.php";
$ok_code = "<xml>
             <return_code><![CDATA[SUCCESS]]></return_code>
            </xml>";
$error_code = "<xml>
                    <return_code><![CDATA[FAIL]]></return_code>
                        <return_msg><![CDATA[NO]]></return_msg>
                    </xml>";
$xml = file_get_contents("php://input");;
$info = xmlToArray($xml);
//判断微信返回信息
if ($info['return_code'] == 'SUCCESS' && $info['result_code'] == "SUCCESS") {
    $order = new OrderClass();
    $obj = GetObjectBySql("select * from vmp_order where order_sn=" . $info['out_trade_no'] . " and pay_status=0", "OrderClass");
    if ($obj) {
        $sign = $info['sign'];
        unset($info['sign']);
        $WxPay = load_wechat('pay');
        $new_sign = \Wechat\Lib\Tools::getPaySign($info, $WxPay->partnerKey);
        //对比签名
        if ($sign != $new_sign) {

            return $error_code;
        }
        $obj->pay_status = 1;
        //更新一支付
        $result = ObjectSqlUpdate($obj, 'vmp_order');
        if ($result) {
            return $ok_code;
        }
    } else {

        return $error_code;
    }
} else {
    return $error_code;
}

?>